
 <!DOCTYPE HTML>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  
    <title>Angular使用笔记6--编写异步提交带图片的表单服务 | Here. There.</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=3, minimum-scale=1">
    
    <meta name="author" content="被删">
    
    <meta name="description" content="最近的一个项目使用AngularJS(v1.2.6)作为前端的框架，《Angular使用笔记》系列用于记录过程中的一些使用和解决方法。本文记录编写异步提交带图片的表单服务的过程，同时简单介绍$q服务，以及HTML5 File API和FormData。">
    
    
    
    
    <link rel="alternate" href="/atom.xml" title="Here. There." type="application/atom+xml">
    
    
    <link rel="icon" href="/img/favicon.ico">
    
    
    <link rel="apple-touch-icon" href="/img/pacman.jpg">
    <link rel="apple-touch-icon-precomposed" href="/img/pacman.jpg">
    
    <link rel="stylesheet" href="/css/style.css">
    
<script type="text/javascript">
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "//hm.baidu.com/hm.js?3d902de4a19cf2bf179534ffd2dd7b7f";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>

</head>

  <body>
    <header>
      <div>
		
			<div id="imglogo">
				<a href="/"><img src="/img/sun.png" alt="Here. There." title="Here. There."/></a>
			</div>
			
			<div id="textlogo">
				<h1 class="site-name"><a href="/" title="Here. There.">Here. There.</a></h1>
				<h2 class="blog-motto">Love ice cream. Love sunshine. Love life. Love the world. Love myself. Love you.</h2>
			</div>
			<div class="navbar"><a class="navbutton navmobile" href="#" title="菜单">
			</a></div>
			<nav class="animated">
				<ul>
					
						<li><a href="/">首页</a></li>
					
						<li><a href="https://github.com/godbasin/godbasin.github.io">所有文章</a></li>
					
						<li><a href="/archives">归档</a></li>
					
						<li><a href="/categories">分类</a></li>
					
						<li><a href="https://godbasin.github.io/front-end-playground">前端游乐场</a></li>
					
						<li><a href="/about">关于我</a></li>
					
				</ul>
			</nav>			
</div>

    </header>
    <div id="container">
      <div id="main" class="post" itemscope itemprop="blogPost">
	<article itemprop="articleBody"> 
		<header class="article-info clearfix">
  <h1 itemprop="name">
    
      <a href="/2016/07/17/angular-note-6-asyncchronous-submit-form/" title="Angular使用笔记6--编写异步提交带图片的表单服务" itemprop="url">Angular使用笔记6--编写异步提交带图片的表单服务</a>
  </h1>
  <p class="article-author">By
    
      <a href="https://godbasin.github.io" title="被删">被删</a>
    </p>
  <p class="article-time">
    <time datetime="2016-07-17T12:52:25.000Z" itemprop="datePublished">2016-07-17</time>
    更新日期:<time datetime="2017-02-17T13:49:48.675Z" itemprop="dateModified">2017-02-17</time>
    
  </p>
</header>
	<div class="article-content">
		
		
		<div id="toc" class="toc-article">
			<strong class="toc-title">文章目录</strong>
		<ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#有关angularJS-http和-q"><span class="toc-number">1.</span> <span class="toc-text">有关angularJS$http和$q</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#http"><span class="toc-number">1.1.</span> <span class="toc-text">$http</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Promise对象"><span class="toc-number">1.2.</span> <span class="toc-text">Promise对象</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#在AngularJS中使用Promise-q"><span class="toc-number">1.3.</span> <span class="toc-text">在AngularJS中使用Promise: $q</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#编写一个集成-q服务"><span class="toc-number">1.4.</span> <span class="toc-text">编写一个集成$q服务</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#参考"><span class="toc-number">1.5.</span> <span class="toc-text">参考</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#异步提交带图片的表单"><span class="toc-number">2.</span> <span class="toc-text">异步提交带图片的表单</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#XMLHttpRequest-Level-2"><span class="toc-number">2.1.</span> <span class="toc-text">XMLHttpRequest Level 2</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#FormData对象"><span class="toc-number">2.2.</span> <span class="toc-text">FormData对象</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#File-API"><span class="toc-number">2.3.</span> <span class="toc-text">File API</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#编写异步提交带图片表单的服务"><span class="toc-number">2.4.</span> <span class="toc-text">编写异步提交带图片表单的服务</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#使用异步提交带图片表单的服务"><span class="toc-number">2.5.</span> <span class="toc-text">使用异步提交带图片表单的服务</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#结束语"><span class="toc-number">3.</span> <span class="toc-text">结束语</span></a></li></ol>
		</div>
		
		<p>最近的一个项目使用AngularJS(v1.2.6)作为前端的框架，《Angular使用笔记》系列用于记录过程中的一些使用和解决方法。<br>本文记录编写异步提交带图片的表单服务的过程，同时简单介绍$q服务，以及HTML5 File API和FormData。<br><a id="more"></a></p>
<h2 id="有关angularJS-http和-q"><a href="#有关angularJS-http和-q" class="headerlink" title="有关angularJS$http和$q"></a>有关angularJS$http和$q</h2><hr>
<h3 id="http"><a href="#http" class="headerlink" title="$http"></a>$http</h3><ul>
<li>$http是一个用于读取web服务器上数据的服务</li>
<li>$http.get()从web服务器上读取静态JSON数据</li>
<li>$http的post使用会与ajax不一样哦，需要设置Content-Type值，具体可以查看<a href="/2016/07/08/angular-note-2-create-login/">《Angular使用笔记2–创建登录页面》</a>里的解决办法</li>
</ul>
<h3 id="Promise对象"><a href="#Promise对象" class="headerlink" title="Promise对象"></a>Promise对象</h3><p>Javascript采用回调函数(callback)来处理异步编程。从同步编程到异步回调编程有一个适应的过程，但是如果出现多层回调嵌套，也就是我们常说的厄运的回调金字塔(Pyramid of Doom)。</p>
<ul>
<li>Promise是一种异步方式处理值（或者非值）的方法</li>
<li>Promise允许以一种同步的方式编写异步代码</li>
<li>代表了一个函数最终可能的返回值或者抛出的异常</li>
<li>Promises/A规范<ul>
<li>promise有三种状态：未完成(unfulfilled)，完成(fulfilled) 和失败(failed)</li>
<li>promise的状态只能由未完成转换成完成，或者未完成转换成失败</li>
<li>promise的状态转换只发生一次</li>
</ul>
</li>
</ul>
<h3 id="在AngularJS中使用Promise-q"><a href="#在AngularJS中使用Promise-q" class="headerlink" title="在AngularJS中使用Promise: $q"></a>在AngularJS中使用Promise: $q</h3><p>$q是Angular的一种内置服务，它可以使你异步地执行函数，并且当函数执行完成时它允许你使用函数的返回值（或异常）</p>
<ul>
<li><p>$q常用的几个方法</p>
<ul>
<li>defer() 创建一个deferred对象，这个对象可以执行几个常用的方法，比如resolve,reject,notify等</li>
<li>all() 传入Promise的数组，批量执行，返回一个promise对象</li>
<li>when() 传入一个不确定的参数，如果符合Promise标准，就返回一个promise对象</li>
</ul>
</li>
<li><p>defer()方法</p>
<ul>
<li>在$q中，可以使用resolve方法，变成完成状态；使用reject方法，变成拒绝状态</li>
<li>defer()用于创建一个deferred对象，defer.promise用于返回一个promise对象，来定义then方法</li>
<li>then中有三个参数，分别是成功回调、失败回调、状态变更回调</li>
</ul>
</li>
<li><p>all()方法</p>
<ul>
<li>可以把多个primise的数组合并成一个</li>
<li>当所有的promise执行成功后，会执行后面的回调</li>
</ul>
</li>
<li><p>when()方法</p>
<ul>
<li>可以传入一个参数，这个参数可能是一个值，可能是一个符合promise标准的外部对象</li>
</ul>
</li>
</ul>
<h3 id="编写一个集成-q服务"><a href="#编写一个集成-q服务" class="headerlink" title="编写一个集成$q服务"></a>编写一个集成$q服务</h3><p>这里我们将单个$q服务和多个$q服务（all()方法）集成成一个服务，返回Promise</p>
<ul>
<li>query方法<ul>
<li>query方法返回一个对象，对象包括单个$http请求的Promise以及取消请求的方法</li>
<li>multiquery方法返回多个$http请求的promise</li>
</ul>
</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div></pre></td><td class="code"><pre><div class="line">app.factory(<span class="string">'qService'</span>, [<span class="string">'$http'</span>, <span class="string">'$q'</span>, <span class="function"><span class="keyword">function</span>(<span class="params">$http, $q</span>) </span>&#123;</div><div class="line">  <span class="keyword">return</span> &#123;</div><div class="line">    <span class="attr">query</span>: <span class="function"><span class="keyword">function</span>(<span class="params">param</span>) </span>&#123;</div><div class="line">      <span class="keyword">var</span> deferred = $q.defer(), <span class="comment">//声明承诺</span></div><div class="line">        cancel = <span class="function"><span class="keyword">function</span>(<span class="params">reason</span>) </span>&#123; <span class="comment">//取消promise事件</span></div><div class="line">          deferred.reject(reason);</div><div class="line">        &#125;;</div><div class="line">      $http(param).</div><div class="line">      success(<span class="function"><span class="keyword">function</span>(<span class="params">data</span>) </span>&#123;</div><div class="line">        deferred.resolve(data); <span class="comment">//请求成功</span></div><div class="line">      &#125;).</div><div class="line">      error(<span class="function"><span class="keyword">function</span>(<span class="params">data</span>) </span>&#123;</div><div class="line">        deferred.reject(data); <span class="comment">//请求失败</span></div><div class="line">      &#125;);</div><div class="line">      <span class="keyword">return</span> &#123;</div><div class="line">        <span class="attr">promise</span>: deferred.promise, <span class="comment">// 返回承诺</span></div><div class="line">        cancel: cancel <span class="comment">// 返回取消事件</span></div><div class="line">      &#125;;</div><div class="line">    &#125;,</div><div class="line">    <span class="attr">multiquery</span>: <span class="function"><span class="keyword">function</span>(<span class="params">params</span>) </span>&#123;</div><div class="line">      <span class="keyword">var</span> promises = [];</div><div class="line">      <span class="keyword">for</span> (<span class="keyword">var</span> i <span class="keyword">in</span> params) &#123;</div><div class="line">        <span class="keyword">var</span> promise = $http(params[i]); <span class="comment">//返回$http服务</span></div><div class="line">        promises.push(promise); <span class="comment">//将$http服务添加进队列</span></div><div class="line">      &#125;</div><div class="line">      <span class="keyword">return</span> $q.all(promises); <span class="comment">//返回Promise承诺</span></div><div class="line">    &#125;</div><div class="line">  &#125;;</div><div class="line">&#125;])</div></pre></td></tr></table></figure>
<p>注意：</p>
<ul>
<li>这里取消promise的事件只适合GET请求，若在POST请求上请求可能会导致不可预测的错误哦</li>
<li>多个http服务的请求的错误回调本骚年还没想到解决办法，请小伙伴们多多赐教</li>
</ul>
<h3 id="参考"><a href="#参考" class="headerlink" title="参考"></a>参考</h3><ul>
<li><a href="http://www.cnblogs.com/xing901022/p/4928147.html" target="_blank" rel="external">《AngularJS 中的Promise — $q服务详解》</a></li>
<li><a href="https://blog.coding.net/blog/how-do-promises-work" target="_blank" rel="external">《理解 Promise 的工作原理》</a></li>
</ul>
<h2 id="异步提交带图片的表单"><a href="#异步提交带图片的表单" class="headerlink" title="异步提交带图片的表单"></a>异步提交带图片的表单</h2><hr>
<p>在Angular中要实现异步提交图片，可以使用组件或者利用HTML5属性formdata和fileapi自己实现图片的提交哦。</p>
<ul>
<li>Angular的组件或者服务本骚年木有找到…</li>
<li>既然已经使用了jQuery，推荐一个异步提交表单的插件jQuery.form</li>
</ul>
<h3 id="XMLHttpRequest-Level-2"><a href="#XMLHttpRequest-Level-2" class="headerlink" title="XMLHttpRequest Level 2"></a>XMLHttpRequest Level 2</h3><ul>
<li>XMLHttpRequest是一个浏览器接口，使得Javascript可以进行HTTP(S)通信</li>
<li>新版本的XMLHttpRequest对象(XMLHttpRequest Level 2)功能<ul>
<li>1.可以设置HTTP请求的时限</li>
<li>2.可以使用FormData对象管理表单数据</li>
<li>3.可以上传文件</li>
<li>4.可以请求不同域名下的数据（跨域资源共享，Cross-origin resource sharing，简称CORS）</li>
<li>5.可以获取服务器端的二进制数据</li>
<li>6.可以获得数据传输的进度信息</li>
</ul>
</li>
</ul>
<p>这里主要使用FromData，具体其他请查看<a href="http://www.cnblogs.com/heyuquan/archive/2013/05/13/3076465.html" target="_blank" rel="external">《触碰jQuery：AJAX异步详解》</a></p>
<h3 id="FormData对象"><a href="#FormData对象" class="headerlink" title="FormData对象"></a>FormData对象</h3><p>HTML5新增了一个FormData对象，可以模拟表单<br>使用方法如下：<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div></pre></td><td class="code"><pre><div class="line"><span class="built_in">window</span>.FormData <span class="comment">//检测兼容性</span></div><div class="line"><span class="keyword">var</span> formData = <span class="keyword">new</span> FormData(); <span class="comment">//新建FormData对象</span></div><div class="line">formData.append(name, value); <span class="comment">//添加表单项</span></div><div class="line">xhr.send(formData); <span class="comment">//发送FormData对象</span></div><div class="line"><span class="comment">//以下方法可直接获取网页表单的值</span></div><div class="line"><span class="keyword">var</span> form = <span class="built_in">document</span>.getElementById(<span class="string">'form'</span>); <span class="comment">//获取form对象</span></div><div class="line"><span class="keyword">var</span> formData = <span class="keyword">new</span> FormData(form); <span class="comment">//生成FormData对象</span></div><div class="line">formData.append(name, value); <span class="comment">// 添加表单项</span></div><div class="line">xhr.open(<span class="string">'POST'</span>, form.action);</div><div class="line">xhr.send(formData);<span class="comment">//发送FormData对象</span></div></pre></td></tr></table></figure></p>
<h3 id="File-API"><a href="#File-API" class="headerlink" title="File API"></a>File API</h3><p>HTML5提供了File API，允许js读取本地文件。主要用于本地预览图片。</p>
<ul>
<li>FileList接口: 可以用来代表一组文件的JS对象，比如用户通过input[type=”file”]元素选中的本地文件列表</li>
<li>Blob接口: 用来代表一段二进制数据，并且允许我们通过JS对其数据以字节为单位进行“切割”</li>
<li>File接口: 用来代步一个文件，是从Blob接口继承而来的，并在此基础上增加了诸如文件名、MIME类型之类的特性</li>
<li>FileReader接口: 提供读取文件的方法和事件</li>
<li>检查File API兼容性： window.File&amp;&amp;window.FileReader&amp;&amp;window.FileList&amp;&amp;window.Blob</li>
</ul>
<p>其他方法可参考<a href="http://bulaoge.net/topic.blg?dmn=g3g4&amp;tid=2344378#Content" target="_blank" rel="external">《HTML 5中的文件处理之FileAPI》</a></p>
<h3 id="编写异步提交带图片表单的服务"><a href="#编写异步提交带图片表单的服务" class="headerlink" title="编写异步提交带图片表单的服务"></a>编写异步提交带图片表单的服务</h3><p>现在我们利用FormData和FileAPI，可以开始编写异步提交带图片表单的服务了。<br>添加工厂服务，代码如下：<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div></pre></td><td class="code"><pre><div class="line"><span class="comment">/* params:</span></div><div class="line"> * &#123;</div><div class="line"> * 	fileinput: 传入file input的dom对象,</div><div class="line"> * 	url: 服务器地址,</div><div class="line"> * 	other: 其他需要发送的参数&#123;键：值&#125;</div><div class="line"> *  callback: 成功回调</div><div class="line"> *  errback: 失败回调</div><div class="line"> * &#125;</div><div class="line"> */</div><div class="line">.factory(<span class="string">'AsyncForm'</span>, <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</div><div class="line">  <span class="keyword">var</span> feature = &#123;&#125;; <span class="comment">//用于检查FormData和fileAPI的兼容性</span></div><div class="line">  feature.fileapi = (<span class="built_in">window</span>.File &amp;&amp; <span class="built_in">window</span>.FileReader &amp;&amp; <span class="built_in">window</span>.FileList &amp;&amp; <span class="built_in">window</span>.Blob);</div><div class="line">  feature.formdata = <span class="built_in">window</span>.FormData !== <span class="literal">undefined</span>;</div><div class="line">  <span class="keyword">var</span> fileAPI = feature.fileapi &amp;&amp; feature.formdata,</div><div class="line">    formData,</div><div class="line">    xhr = <span class="built_in">window</span>.XMLHttpRequest ? <span class="keyword">new</span> XMLHttpRequest() : <span class="keyword">new</span> ActiveXObject(<span class="string">'Microsoft.XMLHTTP'</span>),</div><div class="line">    AsyncForm = <span class="function"><span class="keyword">function</span>(<span class="params">params</span>) </span>&#123;</div><div class="line">      <span class="keyword">if</span> (fileAPI) &#123;</div><div class="line">        <span class="keyword">var</span> otherparams = params.other, <span class="comment">//其他需要发送的参数&#123;键：值&#125;</span></div><div class="line">          callback = params.callback, <span class="comment">//成功回调</span></div><div class="line">          errback = params.errback, <span class="comment">//失败回调</span></div><div class="line">          files = (params.fileinput &amp;&amp; params.fileinput.files) ? params.fileinput.files : &#123;&#125;, <span class="comment">//传入file input的dom对象</span></div><div class="line">          onreadystatechange;</div><div class="line">        <span class="comment">//设置onreadystatechange</span></div><div class="line">        onreadystatechange = <span class="function"><span class="keyword">function</span>(<span class="params">func, _xhr, errfunc</span>) </span>&#123;</div><div class="line">          _xhr.onreadystatechange = <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</div><div class="line">            <span class="keyword">if</span> (_xhr.readyState == <span class="number">4</span>) &#123;</div><div class="line">              <span class="keyword">if</span> (_xhr.status == <span class="number">200</span>) &#123;</div><div class="line">                <span class="comment">//判断若有成功回调，则执行</span></div><div class="line">                <span class="keyword">if</span> (<span class="keyword">typeof</span> func == <span class="string">'function'</span>) &#123;func(_xhr.responseText);&#125; </div><div class="line">              &#125; <span class="keyword">else</span> &#123;</div><div class="line">                <span class="comment">//判断若有失败回调，则执行</span></div><div class="line">                <span class="keyword">if</span> (<span class="keyword">typeof</span> errfunc == <span class="string">'function'</span>) &#123;errfunc();&#125;</div><div class="line">              &#125;</div><div class="line">            &#125;</div><div class="line">          &#125;</div><div class="line">        &#125;;</div><div class="line">        <span class="comment">//新建formData对象</span></div><div class="line">        formData = <span class="keyword">new</span> FormData();</div><div class="line">        <span class="comment">//判断是否有图片对象，有则添加进队列</span></div><div class="line">        <span class="keyword">if</span> (files) &#123;</div><div class="line">          <span class="keyword">for</span> (<span class="keyword">var</span> i = <span class="number">0</span>; i &lt; files.length; i++) &#123;</div><div class="line">            formData.append(<span class="string">'file'</span>, files[i]);</div><div class="line">          &#125;</div><div class="line">        &#125;</div><div class="line">        <span class="comment">//若有其他表单项，添加进队列</span></div><div class="line">        <span class="keyword">for</span> (i <span class="keyword">in</span> otherparams) &#123;</div><div class="line">          formData.append(i, otherparams[i]);</div><div class="line">        &#125;</div><div class="line">        <span class="comment">//设置POST方法，以及服务器地址</span></div><div class="line">        xhr.open(<span class="string">'post'</span>, params.url);</div><div class="line">        onreadystatechange(callback, xhr, errback);</div><div class="line">      &#125; <span class="keyword">else</span> &#123;</div><div class="line">        alert(<span class="string">"浏览器不支持FormData或fileAPI"</span>);</div><div class="line">      &#125;</div><div class="line">    &#125;;</div><div class="line">  AsyncForm.prototype = &#123;</div><div class="line">    <span class="comment">//提交表单事件</span></div><div class="line">    submit: <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</div><div class="line">      xhr.send(formData);</div><div class="line">    &#125;,</div><div class="line">  &#125;;</div><div class="line">  <span class="keyword">return</span> AsyncForm;</div><div class="line">&#125;);</div></pre></td></tr></table></figure></p>
<ul>
<li>这里的fileinput参数传入file input的dom对象，其实可以直接传入file的，大家可以进行优化哦。</li>
</ul>
<h3 id="使用异步提交带图片表单的服务"><a href="#使用异步提交带图片表单的服务" class="headerlink" title="使用异步提交带图片表单的服务"></a>使用异步提交带图片表单的服务</h3><ul>
<li>在控制器中需注入依赖AsyncForm</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line"><span class="comment">//创建表单</span></div><div class="line"><span class="keyword">var</span> asform = <span class="keyword">new</span> AsyncForm(&#123;</div><div class="line">  <span class="attr">fileinput</span>: $input, <span class="comment">//传入file input的dom对象</span></div><div class="line">  url: url, <span class="comment">//服务器地址</span></div><div class="line">  other: &#123; <span class="comment">//其他需要发送的参数&#123;键：值&#125;</span></div><div class="line">    name: value,</div><div class="line">    <span class="attr">name</span>: value,</div><div class="line">  &#125;,</div><div class="line">  <span class="attr">callback</span>: <span class="function"><span class="keyword">function</span>(<span class="params">data</span>) </span>&#123;&#125;, <span class="comment">//成功回调</span></div><div class="line">  errback: <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;&#125; <span class="comment">//失败回调</span></div><div class="line">&#125;);</div><div class="line"><span class="comment">//提交表单</span></div><div class="line">asform.submit();</div></pre></td></tr></table></figure>
<h2 id="结束语"><a href="#结束语" class="headerlink" title="结束语"></a>结束语</h2><hr>
<p>这里没有考虑不支持HTML5时候的处理办法，大家可以私底下试试哦，提示：）可使用iframe实现哦。<br><a href="https://github.com/godbasin/godbasin.github.io/tree/blog-codes/angular-notes/6-asyncchronous-submit-form" target="_blank" rel="external">此处查看项目代码（仅包含app部分）</a></p>
  
		
		<p style="margin-top:50px;">
			查看Github有更多内容噢：<a href="https://github.com/godbasin">https://github.com/godbasin</a>
			<br>
			更欢迎来<a href="https://godbasin.github.io/front-end-playground">被删的前端游乐场</a>边撸猫边学前端噢
		</p>
	</div>
	<img src="https://github-imglib-1255459943.cos.ap-chengdu.myqcloud.com/2code2.jpg" width="200" height="200" style="display:block;margin: 0 auto;" />
	<p style="text-align: center;margin-top: 10px;margin-bottom: 20px;">码生艰难，写文不易，给我家猪囤点猫粮了喵~</p>
	<div class="author-right">
  		<p>作者：被删</p>
  		<p>出处：<a href="https://godbasin.github.io">https://godbasin.github.io</a></p>
  		<p>本文版权归作者所有，欢迎转载，但未经作者同意必须保留此段声明，且在文章页面明显位置给出原文连接，否则保留追究法律责任的权利。</p>
	</div>
		<footer class="article-footer clearfix">

  <div class="article-tags">
  
  <span></span> <a href="/tags/笔记/">笔记</a>
  </div>


<div class="article-categories">
  <span></span>
  <a class="article-category-link" href="/categories/angular混搭/">angular混搭</a>
</div>



<div class="article-share" id="share">

  
<!-- JiaThis Button BEGIN -->
<div class="jiathis_style_24x24">
	<a class="jiathis_button_qzone"></a>
	<a class="jiathis_button_tsina"></a>
	<a class="jiathis_button_tqq"></a>
	<a class="jiathis_button_weixin"></a>
	<a class="jiathis_button_renren"></a>
	<a href="http://www.jiathis.com/share?uid=2134021" class="jiathis jiathis_txt jtico jtico_jiathis" target="_blank"></a>
</div>
<script type="text/javascript">
var jiathis_config = {data_track_clickback:'true'};
</script>
<script type="text/javascript" src="http://v3.jiathis.com/code_mini/jia.js?uid=2134021" charset="utf-8"></script>
<!-- JiaThis Button END -->   


</div>
</footer>   	       
	</article>
	
<nav class="article-nav clearfix">
 
 <div class="prev" >
 <a href="/2016/07/22/angular-note-7-load-image/" title="Angular使用笔记7--使用File API编写预览图片的指令">
  <strong>PREVIOUS:</strong><br/>
  <span>
  Angular使用笔记7--使用File API编写预览图片的指令</span>
</a>
</div>


<div class="next">
<a href="/2016/07/16/angular-note-5-fullfill-index/"  title="Angular使用笔记5--作用域简单分析以及制作index页面">
 <strong>NEXT:</strong><br/> 
 <span>Angular使用笔记5--作用域简单分析以及制作index页面
</span>
</a>
</div>

</nav>

	<!-- 如果不是首页且没使用 `comments: false` 关闭评论，则尝试加载评论 -->

    <!-- 配置中启用多说时，导入相应代码 -->
    


</div>  
      <div class="openaside"><a class="navbutton" href="#" title="显示侧边栏"></a></div>

  <div id="toc" class="toc-aside">
  <strong class="toc-title">文章目录</strong>
  <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#有关angularJS-http和-q"><span class="toc-number">1.</span> <span class="toc-text">有关angularJS$http和$q</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#http"><span class="toc-number">1.1.</span> <span class="toc-text">$http</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Promise对象"><span class="toc-number">1.2.</span> <span class="toc-text">Promise对象</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#在AngularJS中使用Promise-q"><span class="toc-number">1.3.</span> <span class="toc-text">在AngularJS中使用Promise: $q</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#编写一个集成-q服务"><span class="toc-number">1.4.</span> <span class="toc-text">编写一个集成$q服务</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#参考"><span class="toc-number">1.5.</span> <span class="toc-text">参考</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#异步提交带图片的表单"><span class="toc-number">2.</span> <span class="toc-text">异步提交带图片的表单</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#XMLHttpRequest-Level-2"><span class="toc-number">2.1.</span> <span class="toc-text">XMLHttpRequest Level 2</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#FormData对象"><span class="toc-number">2.2.</span> <span class="toc-text">FormData对象</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#File-API"><span class="toc-number">2.3.</span> <span class="toc-text">File API</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#编写异步提交带图片表单的服务"><span class="toc-number">2.4.</span> <span class="toc-text">编写异步提交带图片表单的服务</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#使用异步提交带图片表单的服务"><span class="toc-number">2.5.</span> <span class="toc-text">使用异步提交带图片表单的服务</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#结束语"><span class="toc-number">3.</span> <span class="toc-text">结束语</span></a></li></ol>
  </div>

<div id="asidepart">
<div class="closeaside"><a class="closebutton" href="#" title="隐藏侧边栏"></a></div>
<aside class="clearfix">

  	
	<div class="archiveslist">
		<p class="asidetitle">最近文章</p>
			<ul class="archive-list">
			
					
				<li class="archive-list-item">
					<a class="archive-list-link" href="/2019/11/15/wxapp-latest-20191115/" title="小程序开发月刊第11期（20191115）">小程序开发月刊第11期（201911...</a>
				</li>
				
			
					
				<li class="archive-list-item">
					<a class="archive-list-link" href="/2019/11/10/change-log/" title="前端 CHANGELOG 生成指南">前端 CHANGELOG 生成指南...</a>
				</li>
				
			
					
				<li class="archive-list-item">
					<a class="archive-list-link" href="/2019/11/09/wxapp-global-data-behavior/" title="小程序的奇技淫巧 -- globalDataBehavior管理全局状态">小程序的奇技淫巧 -- global...</a>
				</li>
				
			
					
				<li class="archive-list-item">
					<a class="archive-list-link" href="/2019/10/15/wxapp-latest-20191015/" title="小程序开发月刊第十期（20191015）">小程序开发月刊第十期（2019101...</a>
				</li>
				
			
					
				<li class="archive-list-item">
					<a class="archive-list-link" href="/2019/10/13/about-front-end-3-growth/" title="前端这几年--3.关于成长和焦虑">前端这几年--3.关于成长和焦虑...</a>
				</li>
				
			
					
				<li class="archive-list-item">
					<a class="archive-list-link" href="/2019/09/16/wxapp-latest-20190916/" title="小程序开发月刊第九期（20190916）">小程序开发月刊第九期（2019091...</a>
				</li>
				
			
					
				<li class="archive-list-item">
					<a class="archive-list-link" href="/2019/08/15/wxapp-latest-20190815/" title="小程序开发月刊第八期（20190815）">小程序开发月刊第八期（2019081...</a>
				</li>
				
			
					
				<li class="archive-list-item">
					<a class="archive-list-link" href="/2019/07/27/front-end-playground/" title="被删的前端游乐场建成！">被删的前端游乐场建成！</a>
				</li>
				
			
					
				<li class="archive-list-item">
					<a class="archive-list-link" href="/2019/07/21/vue-for-everyone-3/" title="9102全员学Vue--3.把页面拼成个Web应用">9102全员学Vue--3.把页面拼...</a>
				</li>
				
			
					
				<li class="archive-list-item">
					<a class="archive-list-link" href="/2019/07/15/wxapp-latest-20190715/" title="小程序开发月刊第七期（20190715）">小程序开发月刊第七期（2019071...</a>
				</li>
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
			</ul>
	</div>


  
  <div class="archiveslist">
    <p class="asidetitle"><a href="/archives">归档</a></p>
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/11/">十一月 2019</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/10/">十月 2019</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/09/">九月 2019</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/08/">八月 2019</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/07/">七月 2019</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/06/">六月 2019</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/05/">五月 2019</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/04/">四月 2019</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/03/">三月 2019</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/02/">二月 2019</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/01/">一月 2019</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/12/">十二月 2018</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/11/">十一月 2018</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/10/">十月 2018</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/09/">九月 2018</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/08/">八月 2018</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/07/">七月 2018</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/06/">六月 2018</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/05/">五月 2018</a><span class="archive-list-count">5</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/04/">四月 2018</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/03/">三月 2018</a><span class="archive-list-count">7</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/02/">二月 2018</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/01/">一月 2018</a><span class="archive-list-count">9</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/12/">十二月 2017</a><span class="archive-list-count">5</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/11/">十一月 2017</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/10/">十月 2017</a><span class="archive-list-count">5</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/09/">九月 2017</a><span class="archive-list-count">6</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/08/">八月 2017</a><span class="archive-list-count">11</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/07/">七月 2017</a><span class="archive-list-count">9</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/06/">六月 2017</a><span class="archive-list-count">10</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/05/">五月 2017</a><span class="archive-list-count">15</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/04/">四月 2017</a><span class="archive-list-count">7</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/03/">三月 2017</a><span class="archive-list-count">10</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/02/">二月 2017</a><span class="archive-list-count">41</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/01/">一月 2017</a><span class="archive-list-count">6</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/12/">十二月 2016</a><span class="archive-list-count">7</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/11/">十一月 2016</a><span class="archive-list-count">9</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/10/">十月 2016</a><span class="archive-list-count">5</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/09/">九月 2016</a><span class="archive-list-count">7</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/08/">八月 2016</a><span class="archive-list-count">9</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/07/">七月 2016</a><span class="archive-list-count">14</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/06/">六月 2016</a><span class="archive-list-count">9</span></li></ul>
  </div>


  
<div class="archiveslist">
	<p class="asidetitle"><a href="/categories">分类</a></p>
		<ul class="archive-list">
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/CSS炒饭/" title="CSS炒饭">CSS炒饭<sup>3</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/D3小馒头/" title="D3小馒头">D3小馒头<sup>8</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/angular2火锅/" title="angular2火锅">angular2火锅<sup>25</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/angular混搭/" title="angular混搭">angular混搭<sup>33</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/box2djs方糖/" title="box2djs方糖">box2djs方糖<sup>34</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/cyclejs哈根达斯/" title="cyclejs哈根达斯">cyclejs哈根达斯<sup>8</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/jQuery杂烩/" title="jQuery杂烩">jQuery杂烩<sup>3</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/js什锦/" title="js什锦">js什锦<sup>26</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/react沙拉/" title="react沙拉">react沙拉<sup>16</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/three-js奶茶/" title="three.js奶茶">three.js奶茶<sup>5</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/vue八宝粥/" title="vue八宝粥">vue八宝粥<sup>29</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/webpack宾治/" title="webpack宾治">webpack宾治<sup>9</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/web乱炖/" title="web乱炖">web乱炖<sup>2</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/前端满汉全席/" title="前端满汉全席">前端满汉全席<sup>8</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/喵/" title="喵">喵<sup>2</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/小程序双皮奶/" title="小程序双皮奶">小程序双皮奶<sup>27</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/工作这杯茶/" title="工作这杯茶">工作这杯茶<sup>5</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/应用巧克力盒/" title="应用巧克力盒">应用巧克力盒<sup>2</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/思想棉花糖/" title="思想棉花糖">思想棉花糖<sup>8</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/柴米油盐工具集/" title="柴米油盐工具集">柴米油盐工具集<sup>1</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/自动化甜筒/" title="自动化甜筒">自动化甜筒<sup>1</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/非前端钙片/" title="非前端钙片">非前端钙片<sup>7</sup></a>
			</li>
		
		</ul>
</div>


  
<div class="archiveslist">
	<p class="asidetitle">标签</p>
		<ul class="archive-list">
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/tags/分享/" title="分享">分享<sup>44</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/tags/原创部件/" title="原创部件">原创部件<sup>1</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/tags/心态/" title="心态">心态<sup>5</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/tags/教程/" title="教程">教程<sup>73</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/tags/晒猫/" title="晒猫">晒猫<sup>2</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/tags/笔记/" title="笔记">笔记<sup>121</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/tags/算法/" title="算法">算法<sup>9</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/tags/自制插件/" title="自制插件">自制插件<sup>2</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/tags/逻辑实现/" title="逻辑实现">逻辑实现<sup>5</sup></a>
			</li>
		
		</ul>
</div>


    <div class="archiveslist">
    <p class="asidetitle"><a href="/archives">about</a></p>
      <ul class="archive-list">
      	<li class="archive-list-item">
      		<a>wangbeishan@163.com</a>
      		<a href="https://github.com/godbasin">github.com/godbasin</a>
      	</li>
      </ul>
  </div>

  <div class="rsspart">
	<a href="/atom.xml" target="_blank" title="rss">RSS 订阅</a>
</div>

</aside>
</div>
    </div>
    <footer><div id="footer" >
	
	<section class="info">
		<p> 即使梦想再小，却很伟大 ^_^ </p>
	</section>
	 
		<p class="copyright">Powered by <a href="http://hexo.io" target="_blank" title="hexo">hexo</a> and Theme by <a href="https://github.com/A-limon/pacman" target="_blank" title="Pacman">Pacman</a> © 2019 
		
		<a href="https://godbasin.github.io" target="_blank" title="被删">被删</a>
		
		</p>
</div>
</footer>
    <script src="/js/jquery-2.1.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){ 
  $('.navbar').click(function(){
    $('header nav').toggleClass('shownav');
  });
  var myWidth = 0;
  function getSize(){
    if( typeof( window.innerWidth ) == 'number' ) {
      myWidth = window.innerWidth;
    } else if( document.documentElement && document.documentElement.clientWidth) {
      myWidth = document.documentElement.clientWidth;
    };
  };
  var m = $('#main'),
      a = $('#asidepart'),
      c = $('.closeaside'),
      o = $('.openaside');
  $(window).resize(function(){
    getSize(); 
    if (myWidth >= 1024) {
      $('header nav').removeClass('shownav');
    }else
    {
      m.removeClass('moveMain');
      a.css('display', 'block').removeClass('fadeOut');
      o.css('display', 'none');
      
      $('#toc.toc-aside').css('display', 'none');
        
    }
  });
  c.click(function(){
    a.addClass('fadeOut').css('display', 'none');
    o.css('display', 'block').addClass('fadeIn');
    m.addClass('moveMain');
  });
  o.click(function(){
    o.css('display', 'none').removeClass('beforeFadeIn');
    a.css('display', 'block').removeClass('fadeOut').addClass('fadeIn');      
    m.removeClass('moveMain');
  });
  $(window).scroll(function(){
    o.css("top",Math.max(80,260-$(this).scrollTop()));
  });
});
</script>

<script type="text/javascript">
$(document).ready(function(){ 
  var ai = $('.article-content>iframe'),
      ae = $('.article-content>embed'),
      t  = $('#toc'),
      h  = $('article h2')
      ah = $('article h2'),
      ta = $('#toc.toc-aside'),
      o  = $('.openaside'),
      c  = $('.closeaside');
  if(ai.length>0){
    ai.wrap('<div class="video-container" />');
  };
  if(ae.length>0){
   ae.wrap('<div class="video-container" />');
  };
  if(ah.length==0){
    t.css('display','none');
  }else{
    c.click(function(){
      ta.css('display', 'block').addClass('fadeIn');
    });
    o.click(function(){
      ta.css('display', 'none');
    });
    $(window).scroll(function(){
      ta.css("top",Math.max(140,320-$(this).scrollTop()));
    });
  };
});
</script>







  </body>
</html>
